import vue from '@vitejs/plugin-vue'

import createAutoImport from './auto-import'
import createSvgIcon from './svg-icon'
import createCompression from './compression'
import createSetupExtend from './setup-extend'

export default function createVitePlugins(viteEnv, isBuild = false) {
    // 添加 Vue 插件的配置选项
    const vuePluginOptions = {
      compilerOptions: {
        isCustomElement: (tag) => {
          return false
        },
        // 设置默认事件修饰符
        directiveTransforms: {
          on: (dir, node, context) => {
            // 为 wheel 事件添加 passive 修饰符
            if (dir.arg && dir.arg.content === 'wheel') {
              dir.modifiers = dir.modifiers || []
              if (!dir.modifiers.includes('passive')) {
                dir.modifiers.push('passive')
              }
            }
            return dir
          }
        }
      }
    }
    
    const vitePlugins = [vue(vuePluginOptions)]
    vitePlugins.push(createAutoImport())
	vitePlugins.push(createSetupExtend())
    vitePlugins.push(createSvgIcon(isBuild))
	isBuild && vitePlugins.push(...createCompression(viteEnv))
    return vitePlugins
}
